import { createStore } from "vuex";

// 创建一个新的 store 实例
const store = createStore({
    state() {
        return {
            count: 0
        };
    },
    actions: {
        incrementAsync(context, n) {
            // context中有commit state getters 等
            return new Promise(resolve => {
                setTimeout(() => {
                    context.commit("increment", n)
                    resolve("执行成功")
                }, 1000)
            })
        }
    },
    mutations: {
        increment(state, n) {
            state.count = state.count + n
        }
    }
});

export default store;
